package model;

import java.util.List;

import common.GridCoordinate;
import controller.Controller;

/**
 * @author Colin
 * 
 * This class represents the weapons that fire when Zombosaurs 
 * enter the weapons range. This class extends weapon and thhe rate 
 * that the weapon fires is also specified.
 *
 */
public abstract class AutomaticWeapon extends Weapon{
	
	private List<GridCoordinate> range;
	private int rate;
	private boolean fired;
	int lastFiredTick;
	
	//AutomaticWeapon without position
	public AutomaticWeapon(String name, String imageName, String ammoImageName, int cost, int damage, int speed, int rangeInt, int rate){
		super(name, imageName, ammoImageName, cost, damage, speed, rangeInt);
		
		this.rate = rate;
		fired = false;
		int lastFiredTick = 0;
		
	}
	
	//AutomaticWeapon with 
	public AutomaticWeapon( String name, String imageName, String ammoImageName, int cost, GridCoordinate position, int damage, int speed, int rangeInt, int rate){
		super(name, imageName, ammoImageName, cost, position, damage, speed, rangeInt);
		
		this.rate = rate;
		fired = false;
		int lastFiredTick = 0;
	}
	
	@Override
	public List<GridCoordinate> getRange(){
		return range;
	}
	@Override
	public void setRange( List<GridCoordinate> range ){
		this.range = range;
	}
	
	public int getRate(){
		return rate;
	}
	
	public void setRate( int rate ){
		this.rate = rate;
	}
	
	public boolean fireNew(int curTick){
		if(curTick - lastFiredTick >= Controller.ticksPerSecond / rate){
			return true;
		}
		else{
			return false;
		}
	}
	
	public int getLastFiredTick() {
		return lastFiredTick;
	}

	public void setLastFiredTick(int lastFiredTick) {
		this.lastFiredTick = lastFiredTick;
	}

	/**
	 * Rotates the range 90 degrees clockwise.
	 */
	public abstract void rotateCCW();
	
	public String getUsageDescription(){
		return "Click to select weapon, then click on the desired position to place it. It will then fire on attacking zombosaurs automatically. Can't be laid on the trail!";
	}
	
}
